/*
 * @Author: rgoogle rs1766728441@gmail.com
 * @Date: 2023-04-03 15:03:49
 * @LastEditors: rgoogle rs1766728441@gmail.com
 * @LastEditTime: 2023-04-03 15:04:36
 * @FilePath: \main-page\secondterm\compute.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

const readline = require('readline');


const rl = readline.createInterface({

  input: process.stdin,

  output: process.stdout

});



rl.question('请输入一个四则运算式：', (input) => {

  const regex = /^(\d+)\s*([\+\-\*\/])\s*(\d+)$/g;

  const match = regex.exec(input);

  if (match) {

    const num1 = parseInt(match[1]);

    const operator = match[2];

    const num2 = parseInt(match[3]);

    let result;

    switch (operator) {

      case '+':

        result = num1 + num2;

        break;

      case '-':

        result = num1 - num2;

        break;

      case '*':

        result = num1 * num2;

        break;

      case '/':

        if (num2 === 0) {

          console.log('除数不能为0');

          return;

        }

        result = num1 / num2;

        break;

      default:

        console.log('不支持的操作符');

        return;

    }

    console.log(`结果为：${result}`);

  } else {

    console.log('输入格式不正确');

  }

  rl.close();

});